from BugRanker import BugRanker
from Fuzzer import Fuzzer
import string

"""
    In this file we show another use case of our BugRanker.
    The method under test removes every occurence of AUTHOR_NAME from the input.
    
    This scenario shows the disadvantage of our technique when is a dumb fuzzer is employed.
    Most of the fuzzer's outputs are not usable, so only few failing inputs can be found.
"""

AUTHOR_NAME = 'Eve'

def check_text_for_author_name(_, delivered):
    if AUTHOR_NAME in delivered:
        return 'FAIL'
    else:
        return 'PASS'

def remove_author_name(text):
    words = text.split() # <-- bug: using split() is a bad idea if the separator is not known
    output = ''
    for word in words:
        if word != AUTHOR_NAME:
            output += word
    return output

if __name__ == '__main__':
    bugRanker = BugRanker(remove_author_name, check_text_for_author_name)
    """
    However, the following code snippet shows how the above problem can be easily circumvented. 
    Our basic fuzzer supports custom alphabets, which can be used as follows: 
    
    alphabet = eval('['+repr(AUTHOR_NAME)+','+','.join([repr(x) for x in string.printable])+']')
    fuzzer = Fuzzer(alphabet)
    bugRanker.setFuzzer(fuzzer)
    """
    bugRanker.generateChains(50)
    bugRanker.printBugList()
    # BugRanker.dumpBugList('testCase3.txt') # optionally you can store the results in a text file